#include "RectangleMapItem.h"
#include "MapHandle.h"
#include "AbstractPolygonMapItem.h"
#include "MapCalculator.h"
#include <qmath.h>

RectangleMapItem::RectangleMapItem()
: PolygonMapItem(MapItemType::Rectangle)
{
}

RectangleMapItem::RectangleMapItem(const QPointF& leftTop, const QPointF& rightBottom) 
: PolygonMapItem(MapItemType::Rectangle)
{
	QVector<QPointF> points;
	points.push_back(leftTop);
	points.push_back(QPointF(rightBottom.x(), leftTop.y()));
	points.push_back(rightBottom);
	points.push_back(QPointF(leftTop.x(), rightBottom.y()));
	setPoints(points);
}

RectangleMapItem::RectangleMapItem(const QPointF& leftTop, double width, double height)
: PolygonMapItem(MapItemType::Rectangle)
{
	Q_ASSERT(width != 0);
	double insideAngle = atan(height / width);
	qreal azimuth = MapCalculator::radiansToDegree(insideAngle) + 90;

	double distance = sqrt(pow(width, 2) + pow(height,2));
	QPointF rightBottom = MapCalculator::targetPoint(leftTop, azimuth, distance);

	QVector<QPointF> points;
	points.push_back(leftTop);
	points.push_back(QPointF(rightBottom.x(), leftTop.y()));
	points.push_back(rightBottom);
	points.push_back(QPointF(leftTop.x(), rightBottom.y()));
	setPoints(points);
}

RectangleMapItem::~RectangleMapItem()
{

}